 package org.edu.modules.portal.controller;

 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.xiaoymin.knife4j.annotations.ApiSort;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import java.util.Arrays;
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import org.edu.common.api.vo.Result;
 import org.edu.common.aspect.annotation.AutoLog;
 import org.edu.common.system.base.controller.BaseController;
 import org.edu.common.system.query.QueryGenerator;
 import org.edu.modules.portal.entity.VeSiteLink;
 import org.edu.modules.portal.service.IVeSiteLinkService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;















 @Api(tags = {"链接信息"})
 @RestController
 @RequestMapping({"/portal/veSiteLink"})
 @ApiSort(90)
 public class VeSiteLinkController
   extends BaseController<VeSiteLink, IVeSiteLinkService>
 {
   private static final Logger log = LoggerFactory.getLogger(org.edu.modules.portal.controller.VeSiteLinkController.class);






   @Value("${edu.path.urlPre}")
   private String fileUrlPre;






   @Autowired
   private IVeSiteLinkService veSiteLinkService;







   @AutoLog("链接信息列表-分页查询")
   @ApiOperation(value = "分页查询(公开)", notes = "链接信息列表-分页查询")
   @PostMapping({"/publicInfo/list"})
   @ApiImplicitParams({@ApiImplicitParam(name = "cateid", value = "栏目id", required = true), @ApiImplicitParam(name = "title", value = "关键字", required = false)})
   public Result<?> queryPageList(@ApiIgnore VeSiteLink veSiteLink, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
     QueryWrapper<VeSiteLink> queryWrapper = QueryGenerator.initQueryWrapper(veSiteLink, req.getParameterMap());
    Page<Map<String, Object>> page = new Page(pageNo.intValue(), pageSize.intValue());
     queryWrapper.setEntity(veSiteLink);
     IPage<Map<String, Object>> pageList = this.veSiteLinkService.pageMaps((IPage)page, (Wrapper)queryWrapper);
     //lbh 2024/08/09 for (Map<String, String> item : (Iterable<Map<String, String>>)pageList.getRecords()) {   >>>
//       for (Map<String, Object> item : pageList.getRecords()) {
     for (Map<String, Object> item : pageList.getRecords()) {
       if (item.get("sourceFile") != null) {
         item.replace("sourceFile", this.fileUrlPre + item.get("sourceFile"));
       }
     }
     return Result.OK(pageList);
   }






   @AutoLog("链接信息列表-通过id查询")
   @ApiOperation(value = "通过id查询", notes = "链接信息列表-通过id查询")
   @PostMapping({"/queryById"})
   public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
     VeSiteLink veSiteLink = (VeSiteLink)this.veSiteLinkService.getById(id);
     if (veSiteLink == null) {
       return Result.error("未找到对应数据");
     }

     return Result.OK(veSiteLink);
   }






   @AutoLog("链接信息列表-新增信息")
   @ApiOperation(value = "新增信息", notes = "链接信息列表-新增信息")
   @PostMapping({"/add"})
   public Result<?> add(@RequestBody VeSiteLink veSiteLink) {
/* 120 */     if (this.veSiteLinkService.save(veSiteLink)) {
       return Result.OK("添加成功！");
     }
/* 123 */     return Result.error("操作失败");
   }






   @AutoLog("链接信息列表-修改信息")
   @ApiOperation(value = "修改信息", notes = "链接信息列表-修改信息")
   @PostMapping({"/edit"})
   public Result<?> edit(@RequestBody VeSiteLink veSiteLink) {
     if (this.veSiteLinkService.updateById(veSiteLink)) {
       return Result.OK("编辑成功!");
     }
     return Result.error("操作失败");
   }







   @AutoLog("链接信息列表-通过id删除")
   @ApiOperation(value = "通过id删除", notes = "链接信息列表-通过id删除")
   @PostMapping({"/delete"})
   public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
     if (this.veSiteLinkService.removeById(id)) {
       return Result.OK("删除成功!");
     }
/* 154 */     return Result.error("操作失败");
   }






   @AutoLog("链接信息列表-批量删除")
   @ApiOperation(value = "批量删除", notes = "链接信息列表-批量删除")
   @PostMapping({"/deleteBatch"})
   public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
     if (this.veSiteLinkService.removeByIds(Arrays.asList(ids.split(",")))) {
       return Result.OK("批量删除成功!");
     }
/* 169 */     return Result.error("操作失败");
   }
 }



